package itheima.zuoye.test2;

public class Factory {


        public static Payment getInstance(String type) {
            if (type == null) {
                throw new IllegalArgumentException("支付类型不能为空");
            }

            Payment payment;
            switch (type.trim().toLowerCase()) {
                case "wechat":
                    payment = new WechatPay();
                    break;
                case "alipay":
                    payment = new AliPay();
                    break;
                case "bank":
                    payment = new BankPay();
                    break;
                default:
                    throw new IllegalArgumentException("不支持的支付类型: " + type);
            }
            return payment;
        }

    }

